
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.electronic_structure.dos &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.dos</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.electronic_structure.dos</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module defines classes to represent the density of states, etc.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">functools</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">pymatgen.electronic_structure.core</span> <span class="kn">import</span> <span class="n">Spin</span><span class="p">,</span> <span class="n">Orbital</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">get_el_sp</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.spectrum</span> <span class="kn">import</span> <span class="n">Spectrum</span>
<span class="kn">from</span> <span class="nn">pymatgen.util.coord</span> <span class="kn">import</span> <span class="n">get_linear_interpolated_value</span>
<span class="kn">from</span> <span class="nn">scipy.constants.codata</span> <span class="kn">import</span> <span class="n">value</span> <span class="k">as</span> <span class="n">_cd</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2012, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;2.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;shyuep@gmail.com&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Mar 20, 2012&quot;</span>


<div class="viewcode-block" id="DOS"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.DOS">[docs]</a><span class="k">class</span> <span class="nc">DOS</span><span class="p">(</span><span class="n">Spectrum</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Replacement basic DOS object. All other DOS objects are extended versions</span>
<span class="sd">    of this object. Work in progress.</span>

<span class="sd">    .. attribute: energies</span>

<span class="sd">        The sequence of energies</span>

<span class="sd">    .. attribute: densities</span>

<span class="sd">        A dict of spin densities, e.g., {Spin.up: [...], Spin.down: [...]}</span>

<span class="sd">    .. attribute: efermi</span>

<span class="sd">        Fermi level</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">XLABEL</span> <span class="o">=</span> <span class="s2">&quot;Energy&quot;</span>
    <span class="n">YLABEL</span> <span class="o">=</span> <span class="s2">&quot;Density&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">,</span> <span class="n">efermi</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            energies: A sequence of energies</span>
<span class="sd">            densities (ndarray): Either a Nx1 or a Nx2 array. If former, it is</span>
<span class="sd">                interpreted as a Spin.up only density. Otherwise, the first column</span>
<span class="sd">                is interpreted as Spin.up and the other is Spin.down.</span>
<span class="sd">            efermi: Fermi level energy.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">,</span> <span class="n">efermi</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="n">efermi</span>

<div class="viewcode-block" id="DOS.get_interpolated_gap"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.DOS.get_interpolated_gap">[docs]</a>    <span class="k">def</span> <span class="nf">get_interpolated_gap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Expects a DOS object and finds the gap</span>

<span class="sd">        Args:</span>
<span class="sd">            tol: tolerance in occupations for determining the gap</span>
<span class="sd">            abs_tol: Set to True for an absolute tolerance and False for a</span>
<span class="sd">                relative one.</span>
<span class="sd">            spin: Possible values are None - finds the gap in the summed</span>
<span class="sd">                densities, Up - finds the gap in the up spin channel,</span>
<span class="sd">                Down - finds the gap in the down spin channel.</span>

<span class="sd">        Returns:</span>
<span class="sd">            (gap, cbm, vbm):</span>
<span class="sd">                Tuple of floats in eV corresponding to the gap, cbm and vbm.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ydim</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">abs_tol</span><span class="p">:</span>
            <span class="n">tol</span> <span class="o">=</span> <span class="n">tol</span> <span class="o">*</span> <span class="n">tdos</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="n">tdos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">energies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span>
        <span class="n">below_fermi</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">energies</span><span class="p">))</span>
                       <span class="k">if</span> <span class="n">energies</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">tol</span><span class="p">]</span>
        <span class="n">above_fermi</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">energies</span><span class="p">))</span>
                       <span class="k">if</span> <span class="n">energies</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">tol</span><span class="p">]</span>
        <span class="n">vbm_start</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">below_fermi</span><span class="p">)</span>
        <span class="n">cbm_start</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">above_fermi</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">vbm_start</span> <span class="o">==</span> <span class="n">cbm_start</span><span class="p">:</span>
            <span class="k">return</span> <span class="mf">0.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Interpolate between adjacent values</span>
            <span class="n">terminal_dens</span> <span class="o">=</span> <span class="n">tdos</span><span class="p">[</span><span class="n">vbm_start</span><span class="p">:</span><span class="n">vbm_start</span> <span class="o">+</span> <span class="mi">2</span><span class="p">][::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">terminal_energies</span> <span class="o">=</span> <span class="n">energies</span><span class="p">[</span><span class="n">vbm_start</span><span class="p">:</span><span class="n">vbm_start</span> <span class="o">+</span> <span class="mi">2</span><span class="p">][::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">start</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="n">terminal_dens</span><span class="p">,</span>
                                                  <span class="n">terminal_energies</span><span class="p">,</span> <span class="n">tol</span><span class="p">)</span>
            <span class="n">terminal_dens</span> <span class="o">=</span> <span class="n">tdos</span><span class="p">[</span><span class="n">cbm_start</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span><span class="n">cbm_start</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">terminal_energies</span> <span class="o">=</span> <span class="n">energies</span><span class="p">[</span><span class="n">cbm_start</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span><span class="n">cbm_start</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">end</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="n">terminal_dens</span><span class="p">,</span>
                                                <span class="n">terminal_energies</span><span class="p">,</span> <span class="n">tol</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">end</span> <span class="o">-</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">start</span></div>

<div class="viewcode-block" id="DOS.get_cbm_vbm"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.DOS.get_cbm_vbm">[docs]</a>    <span class="k">def</span> <span class="nf">get_cbm_vbm</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Expects a DOS object and finds the cbm and vbm.</span>

<span class="sd">        Args:</span>
<span class="sd">            tol: tolerance in occupations for determining the gap</span>
<span class="sd">            abs_tol: An absolute tolerance (True) and a relative one (False)</span>
<span class="sd">            spin: Possible values are None - finds the gap in the summed</span>
<span class="sd">                densities, Up - finds the gap in the up spin channel,</span>
<span class="sd">                Down - finds the gap in the down spin channel.</span>

<span class="sd">        Returns:</span>
<span class="sd">            (cbm, vbm): float in eV corresponding to the gap</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># determine tolerance</span>
        <span class="k">if</span> <span class="n">spin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ydim</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">spin</span> <span class="o">==</span> <span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">:</span>
            <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">abs_tol</span><span class="p">:</span>
            <span class="n">tol</span> <span class="o">=</span> <span class="n">tol</span> <span class="o">*</span> <span class="n">tdos</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="n">tdos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># find index of fermi energy</span>
        <span class="n">i_fermi</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i_fermi</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">:</span>
            <span class="n">i_fermi</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># work backwards until tolerance is reached</span>
        <span class="n">i_gap_start</span> <span class="o">=</span> <span class="n">i_fermi</span>
        <span class="k">while</span> <span class="n">i_gap_start</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i_gap_start</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">tol</span><span class="p">:</span>
            <span class="n">i_gap_start</span> <span class="o">-=</span> <span class="mi">1</span>

        <span class="c1"># work forwards until tolerance is reached</span>
        <span class="n">i_gap_end</span> <span class="o">=</span> <span class="n">i_gap_start</span>
        <span class="k">while</span> <span class="n">i_gap_end</span> <span class="o">&lt;</span> <span class="n">tdos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i_gap_end</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">tol</span><span class="p">:</span>
            <span class="n">i_gap_end</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">i_gap_end</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i_gap_end</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="p">[</span><span class="n">i_gap_start</span><span class="p">]</span></div>

<div class="viewcode-block" id="DOS.get_gap"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.DOS.get_gap">[docs]</a>    <span class="k">def</span> <span class="nf">get_gap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Expects a DOS object and finds the gap.</span>

<span class="sd">        Args:</span>
<span class="sd">            tol: tolerance in occupations for determining the gap</span>
<span class="sd">            abs_tol: An absolute tolerance (True) and a relative one (False)</span>
<span class="sd">            spin: Possible values are None - finds the gap in the summed</span>
<span class="sd">                densities, Up - finds the gap in the up spin channel,</span>
<span class="sd">                Down - finds the gap in the down spin channel.</span>

<span class="sd">        Returns:</span>
<span class="sd">            gap in eV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="p">(</span><span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm_vbm</span><span class="p">(</span><span class="n">tol</span><span class="p">,</span> <span class="n">abs_tol</span><span class="p">,</span> <span class="n">spin</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">max</span><span class="p">(</span><span class="n">cbm</span> <span class="o">-</span> <span class="n">vbm</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string which can be easily plotted (using gnuplot).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">:</span>
            <span class="n">stringarray</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;#</span><span class="si">{:30s}</span><span class="s2"> </span><span class="si">{:30s}</span><span class="s2"> </span><span class="si">{:30s}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;Energy&quot;</span><span class="p">,</span>
                                                          <span class="s2">&quot;DensityUp&quot;</span><span class="p">,</span>
                                                          <span class="s2">&quot;DensityDown&quot;</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">energy</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">):</span>
                <span class="n">stringarray</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{:.5f}</span><span class="s2"> </span><span class="si">{:.5f}</span><span class="s2"> </span><span class="si">{:.5f}</span><span class="s2">&quot;</span>
                                   <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                           <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">stringarray</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;#</span><span class="si">{:30s}</span><span class="s2"> </span><span class="si">{:30s}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;Energy&quot;</span><span class="p">,</span> <span class="s2">&quot;DensityUp&quot;</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">energy</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">):</span>
                <span class="n">stringarray</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{:.5f}</span><span class="s2"> </span><span class="si">{:.5f}</span><span class="s2">&quot;</span>
                                   <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">stringarray</span><span class="p">)</span></div>


<div class="viewcode-block" id="Dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos">[docs]</a><span class="k">class</span> <span class="nc">Dos</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Basic DOS object. All other DOS objects are extended versions of this</span>
<span class="sd">    object.</span>

<span class="sd">    .. attribute: energies</span>

<span class="sd">        The sequence of energies</span>

<span class="sd">    .. attribute: densities</span>

<span class="sd">        A dict of spin densities, e.g., {Spin.up: [...], Spin.down: [...]}</span>

<span class="sd">    .. attribute: efermi</span>

<span class="sd">        Fermi level</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            efermi: Fermi level energy</span>
<span class="sd">            energies: A sequences of energies</span>
<span class="sd">            densities ({Spin: np.array}): representing the density of states</span>
<span class="sd">                for each Spin.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">=</span> <span class="n">efermi</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">energies</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">densities</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>

<div class="viewcode-block" id="Dos.get_densities"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.get_densities">[docs]</a>    <span class="k">def</span> <span class="nf">get_densities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the density of states for a particular spin.</span>

<span class="sd">        Args:</span>
<span class="sd">            spin: Spin</span>

<span class="sd">        Returns:</span>
<span class="sd">            Returns the density of states for a particular spin. If Spin is</span>
<span class="sd">            None, the sum of all spins is returned.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">elif</span> <span class="n">spin</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">:</span>
                <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">result</span></div>

<div class="viewcode-block" id="Dos.get_smeared_densities"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.get_smeared_densities">[docs]</a>    <span class="k">def</span> <span class="nf">get_smeared_densities</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sigma</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the Dict representation of the densities, {Spin: densities},</span>
<span class="sd">        but with a Gaussian smearing of std dev sigma applied about the fermi</span>
<span class="sd">        level.</span>

<span class="sd">        Args:</span>
<span class="sd">            sigma: Std dev of Gaussian smearing function.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Dict of Gaussian-smeared densities.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">scipy.ndimage.filters</span> <span class="kn">import</span> <span class="n">gaussian_filter1d</span>
        <span class="n">smeared_dens</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)]</span>
        <span class="n">avgdiff</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">diff</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">diff</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">dens</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">smeared_dens</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">gaussian_filter1d</span><span class="p">(</span><span class="n">dens</span><span class="p">,</span> <span class="n">sigma</span> <span class="o">/</span> <span class="n">avgdiff</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">smeared_dens</span></div>

    <span class="k">def</span> <span class="fm">__add__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds two DOS together. Checks that energy scales are the same.</span>
<span class="sd">        Otherwise, a ValueError is thrown.</span>

<span class="sd">        Args:</span>
<span class="sd">            other: Another DOS object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Sum of the two DOSs.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">equal</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">energies</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Energies of both DOS are not compatible!&quot;</span><span class="p">)</span>
        <span class="n">densities</span> <span class="o">=</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">+</span> <span class="n">other</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span>
                     <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">keys</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>

<div class="viewcode-block" id="Dos.get_interpolated_value"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.get_interpolated_value">[docs]</a>    <span class="k">def</span> <span class="nf">get_interpolated_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">energy</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns interpolated density for a particular energy.</span>

<span class="sd">        Args:</span>
<span class="sd">            energy: Energy to return the density for.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">f</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">f</span><span class="p">[</span><span class="n">spin</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                                                    <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">spin</span><span class="p">],</span>
                                                    <span class="n">energy</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">f</span></div>

<div class="viewcode-block" id="Dos.get_interpolated_gap"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.get_interpolated_gap">[docs]</a>    <span class="k">def</span> <span class="nf">get_interpolated_gap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Expects a DOS object and finds the gap</span>

<span class="sd">        Args:</span>
<span class="sd">            tol: tolerance in occupations for determining the gap</span>
<span class="sd">            abs_tol: Set to True for an absolute tolerance and False for a</span>
<span class="sd">                relative one.</span>
<span class="sd">            spin: Possible values are None - finds the gap in the summed</span>
<span class="sd">                densities, Up - finds the gap in the up spin channel,</span>
<span class="sd">                Down - finds the gap in the down spin channel.</span>

<span class="sd">        Returns:</span>
<span class="sd">            (gap, cbm, vbm):</span>
<span class="sd">                Tuple of floats in eV corresponding to the gap, cbm and vbm.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_densities</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">abs_tol</span><span class="p">:</span>
            <span class="n">tol</span> <span class="o">=</span> <span class="n">tol</span> <span class="o">*</span> <span class="n">tdos</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="n">tdos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">energies</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span>
        <span class="n">below_fermi</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">energies</span><span class="p">))</span>
                       <span class="k">if</span> <span class="n">energies</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">tol</span><span class="p">]</span>
        <span class="n">above_fermi</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">energies</span><span class="p">))</span>
                       <span class="k">if</span> <span class="n">energies</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">tol</span><span class="p">]</span>
        <span class="n">vbm_start</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">below_fermi</span><span class="p">)</span>
        <span class="n">cbm_start</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">above_fermi</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">vbm_start</span> <span class="o">==</span> <span class="n">cbm_start</span><span class="p">:</span>
            <span class="k">return</span> <span class="mf">0.0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Interpolate between adjacent values</span>
            <span class="n">terminal_dens</span> <span class="o">=</span> <span class="n">tdos</span><span class="p">[</span><span class="n">vbm_start</span><span class="p">:</span><span class="n">vbm_start</span> <span class="o">+</span> <span class="mi">2</span><span class="p">][::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">terminal_energies</span> <span class="o">=</span> <span class="n">energies</span><span class="p">[</span><span class="n">vbm_start</span><span class="p">:</span><span class="n">vbm_start</span> <span class="o">+</span> <span class="mi">2</span><span class="p">][::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">start</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="n">terminal_dens</span><span class="p">,</span>
                                                  <span class="n">terminal_energies</span><span class="p">,</span> <span class="n">tol</span><span class="p">)</span>
            <span class="n">terminal_dens</span> <span class="o">=</span> <span class="n">tdos</span><span class="p">[</span><span class="n">cbm_start</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span><span class="n">cbm_start</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">terminal_energies</span> <span class="o">=</span> <span class="n">energies</span><span class="p">[</span><span class="n">cbm_start</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span><span class="n">cbm_start</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
            <span class="n">end</span> <span class="o">=</span> <span class="n">get_linear_interpolated_value</span><span class="p">(</span><span class="n">terminal_dens</span><span class="p">,</span>
                                                <span class="n">terminal_energies</span><span class="p">,</span> <span class="n">tol</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">end</span> <span class="o">-</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">start</span></div>

<div class="viewcode-block" id="Dos.get_cbm_vbm"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.get_cbm_vbm">[docs]</a>    <span class="k">def</span> <span class="nf">get_cbm_vbm</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Expects a DOS object and finds the cbm and vbm.</span>

<span class="sd">        Args:</span>
<span class="sd">            tol: tolerance in occupations for determining the gap</span>
<span class="sd">            abs_tol: An absolute tolerance (True) and a relative one (False)</span>
<span class="sd">            spin: Possible values are None - finds the gap in the summed</span>
<span class="sd">                densities, Up - finds the gap in the up spin channel,</span>
<span class="sd">                Down - finds the gap in the down spin channel.</span>

<span class="sd">        Returns:</span>
<span class="sd">            (cbm, vbm): float in eV corresponding to the gap</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># determine tolerance</span>
        <span class="n">tdos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_densities</span><span class="p">(</span><span class="n">spin</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">abs_tol</span><span class="p">:</span>
            <span class="n">tol</span> <span class="o">=</span> <span class="n">tol</span> <span class="o">*</span> <span class="n">tdos</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">/</span> <span class="n">tdos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># find index of fermi energy</span>
        <span class="n">i_fermi</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="n">i_fermi</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">:</span>
            <span class="n">i_fermi</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># work backwards until tolerance is reached</span>
        <span class="n">i_gap_start</span> <span class="o">=</span> <span class="n">i_fermi</span>
        <span class="k">while</span> <span class="n">i_gap_start</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i_gap_start</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">tol</span><span class="p">:</span>
            <span class="n">i_gap_start</span> <span class="o">-=</span> <span class="mi">1</span>

        <span class="c1"># work forwards until tolerance is reached</span>
        <span class="n">i_gap_end</span> <span class="o">=</span> <span class="n">i_gap_start</span>
        <span class="k">while</span> <span class="n">i_gap_end</span> <span class="o">&lt;</span> <span class="n">tdos</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> <span class="n">tdos</span><span class="p">[</span><span class="n">i_gap_end</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">tol</span><span class="p">:</span>
            <span class="n">i_gap_end</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">i_gap_end</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="n">i_gap_end</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="n">i_gap_start</span><span class="p">]</span></div>

<div class="viewcode-block" id="Dos.get_gap"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.get_gap">[docs]</a>    <span class="k">def</span> <span class="nf">get_gap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="mf">0.001</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">spin</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Expects a DOS object and finds the gap.</span>

<span class="sd">        Args:</span>
<span class="sd">            tol: tolerance in occupations for determining the gap</span>
<span class="sd">            abs_tol: An absolute tolerance (True) and a relative one (False)</span>
<span class="sd">            spin: Possible values are None - finds the gap in the summed</span>
<span class="sd">                densities, Up - finds the gap in the up spin channel,</span>
<span class="sd">                Down - finds the gap in the down spin channel.</span>

<span class="sd">        Returns:</span>
<span class="sd">            gap in eV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="p">(</span><span class="n">cbm</span><span class="p">,</span> <span class="n">vbm</span><span class="p">)</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm_vbm</span><span class="p">(</span><span class="n">tol</span><span class="p">,</span> <span class="n">abs_tol</span><span class="p">,</span> <span class="n">spin</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">max</span><span class="p">(</span><span class="n">cbm</span> <span class="o">-</span> <span class="n">vbm</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a string which can be easily plotted (using gnuplot).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">Spin</span><span class="o">.</span><span class="n">down</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">:</span>
            <span class="n">stringarray</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;#</span><span class="si">{:30s}</span><span class="s2"> </span><span class="si">{:30s}</span><span class="s2"> </span><span class="si">{:30s}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;Energy&quot;</span><span class="p">,</span>
                                                          <span class="s2">&quot;DensityUp&quot;</span><span class="p">,</span>
                                                          <span class="s2">&quot;DensityDown&quot;</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">energy</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">):</span>
                <span class="n">stringarray</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{:.5f}</span><span class="s2"> </span><span class="si">{:.5f}</span><span class="s2"> </span><span class="si">{:.5f}</span><span class="s2">&quot;</span>
                                   <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                                           <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">stringarray</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;#</span><span class="si">{:30s}</span><span class="s2"> </span><span class="si">{:30s}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;Energy&quot;</span><span class="p">,</span> <span class="s2">&quot;DensityUp&quot;</span><span class="p">)]</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">energy</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">):</span>
                <span class="n">stringarray</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{:.5f}</span><span class="s2"> </span><span class="si">{:.5f}</span><span class="s2">&quot;</span>
                                   <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">energy</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">stringarray</span><span class="p">)</span>

<div class="viewcode-block" id="Dos.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns Dos object from dict representation of Dos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Dos</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;efermi&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energies&quot;</span><span class="p">],</span>
                   <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">v</span>
                    <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;densities&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span></div>

<div class="viewcode-block" id="Dos.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.Dos.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of Dos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
                <span class="s2">&quot;energies&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">),</span>
                <span class="s2">&quot;densities&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="nb">list</span><span class="p">(</span><span class="n">dens</span><span class="p">)</span>
                              <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">dens</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span></div></div>


<div class="viewcode-block" id="FermiDos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.FermiDos">[docs]</a><span class="k">class</span> <span class="nc">FermiDos</span><span class="p">(</span><span class="n">Dos</span><span class="p">,</span> <span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This wrapper class helps relate the density of states, doping levels</span>
<span class="sd">    (i.e. carrier concentrations) and corresponding fermi levels. A negative</span>
<span class="sd">    doping concentration indicates the majority carriers are electrons</span>
<span class="sd">    (n-type doping); a positive doping concentration indicates holes are the</span>
<span class="sd">    majority carriers (p-type doping).</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dos</span><span class="p">:</span> <span class="n">Dos</span><span class="p">,</span> <span class="n">structure</span><span class="p">:</span> <span class="n">Structure</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                 <span class="n">nelecs</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">bandgap</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            dos: Pymatgen Dos object.</span>
<span class="sd">            structure: A structure. If not provided, the structure</span>
<span class="sd">                of the dos object will be used. If the dos does not have an</span>
<span class="sd">                associated structure object, an error will be thrown.</span>
<span class="sd">            nelecs: The number of electrons included in the energy range of</span>
<span class="sd">                dos. It is used for normalizing the densities. Default is the total</span>
<span class="sd">                number of electrons in the structure.</span>
<span class="sd">            bandgap: If set, the energy values are scissored so that the electronic</span>
<span class="sd">                band gap matches this value.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">dos</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="n">dos</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                         <span class="n">densities</span><span class="o">=</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span>
                                    <span class="n">dos</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>

        <span class="k">if</span> <span class="n">structure</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">dos</span><span class="p">,</span> <span class="s2">&quot;structure&quot;</span><span class="p">):</span>
                <span class="n">structure</span> <span class="o">=</span> <span class="n">dos</span><span class="o">.</span><span class="n">structure</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Structure object is not provided and not &quot;</span>
                                 <span class="s2">&quot;present in dos&quot;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nelecs</span> <span class="o">=</span> <span class="n">nelecs</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">total_electrons</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">volume</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">volume</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">dos</span><span class="o">.</span><span class="n">energies</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">de</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">(</span>
            <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span>

        <span class="c1"># normalize total density of states based on integral at 0K</span>
        <span class="n">tdos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_densities</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tdos</span> <span class="o">=</span> <span class="n">tdos</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">nelecs</span> <span class="o">/</span> <span class="p">(</span><span class="n">tdos</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">de</span><span class="p">)[</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">&lt;=</span>
                                                          <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">]</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span>

        <span class="n">ecbm</span><span class="p">,</span> <span class="n">evbm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cbm_vbm</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">idx_vbm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">-</span> <span class="n">evbm</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">idx_cbm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">-</span> <span class="n">ecbm</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">A_to_cm</span> <span class="o">=</span> <span class="mf">1e-8</span>

        <span class="k">if</span> <span class="n">bandgap</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">evbm</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span> <span class="o">&lt;</span> <span class="n">ecbm</span><span class="p">:</span>
                <span class="n">eref</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">eref</span> <span class="o">=</span> <span class="p">(</span><span class="n">evbm</span> <span class="o">+</span> <span class="n">ecbm</span><span class="p">)</span> <span class="o">/</span> <span class="mf">2.0</span>

            <span class="n">idx_fermi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span> <span class="o">-</span> <span class="n">eref</span><span class="p">))</span>

            <span class="k">if</span> <span class="n">idx_fermi</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">idx_vbm</span><span class="p">:</span>
                <span class="c1"># Fermi level and vbm should be different indices</span>
                <span class="n">idx_fermi</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[:</span><span class="n">idx_fermi</span><span class="p">]</span> <span class="o">-=</span> <span class="p">(</span><span class="n">bandgap</span> <span class="o">-</span> <span class="p">(</span><span class="n">ecbm</span> <span class="o">-</span> <span class="n">evbm</span><span class="p">))</span> <span class="o">/</span> <span class="mf">2.0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="n">idx_fermi</span><span class="p">:]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">bandgap</span> <span class="o">-</span> <span class="p">(</span><span class="n">ecbm</span> <span class="o">-</span> <span class="n">evbm</span><span class="p">))</span> <span class="o">/</span> <span class="mf">2.0</span>

<div class="viewcode-block" id="FermiDos.get_doping"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.FermiDos.get_doping">[docs]</a>    <span class="k">def</span> <span class="nf">get_doping</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fermi_level</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">temperature</span><span class="p">:</span> <span class="nb">float</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculate the doping (majority carrier concentration) at a given</span>
<span class="sd">        fermi level  and temperature. A simple Left Riemann sum is used for</span>
<span class="sd">        integrating the density of states over energy &amp; equilibrium Fermi-Dirac</span>
<span class="sd">        distribution.</span>

<span class="sd">        Args:</span>
<span class="sd">            fermi_level: The fermi_level level in eV.</span>
<span class="sd">            temperature: The temperature in Kelvin.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The doping concentration in units of 1/cm^3. Negative values</span>
<span class="sd">            indicate that the majority carriers are electrons (n-type doping)</span>
<span class="sd">            whereas positivie values indicates the majority carriers are holes</span>
<span class="sd">            (p-type doping).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cb_integral</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tdos</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">idx_cbm</span><span class="p">:]</span>
            <span class="o">*</span> <span class="n">f0</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">idx_cbm</span><span class="p">:],</span> <span class="n">fermi_level</span><span class="p">,</span> <span class="n">temperature</span><span class="p">)</span>
            <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">de</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">idx_cbm</span><span class="p">:],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">vb_integral</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tdos</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">idx_vbm</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">*</span>
            <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">f0</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">idx_vbm</span> <span class="o">+</span> <span class="mi">1</span><span class="p">],</span> <span class="n">fermi_level</span><span class="p">,</span> <span class="n">temperature</span><span class="p">))</span>
            <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">de</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">idx_vbm</span> <span class="o">+</span> <span class="mi">1</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">vb_integral</span> <span class="o">-</span> <span class="n">cb_integral</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">volume</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">A_to_cm</span> <span class="o">**</span> <span class="mi">3</span><span class="p">)</span></div>

<div class="viewcode-block" id="FermiDos.get_fermi_interextrapolated"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.FermiDos.get_fermi_interextrapolated">[docs]</a>    <span class="k">def</span> <span class="nf">get_fermi_interextrapolated</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">concentration</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
                                    <span class="n">temperature</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">warn</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
                                    <span class="n">c_ref</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">1e10</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">float</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Similar to get_fermi except that when get_fermi fails to converge,</span>
<span class="sd">        an interpolated or extrapolated fermi is returned with the assumption</span>
<span class="sd">        that the fermi level changes linearly with log(abs(concentration)).</span>

<span class="sd">        Args:</span>
<span class="sd">            concentration: The doping concentration in 1/cm^3. Negative values</span>
<span class="sd">                represent n-type doping and positive values represent p-type</span>
<span class="sd">                doping.</span>
<span class="sd">            temperature: The temperature in Kelvin.</span>
<span class="sd">            warn: Whether to give a warning the first time the fermi cannot be</span>
<span class="sd">                found.</span>
<span class="sd">            c_ref: A doping concentration where get_fermi returns a</span>
<span class="sd">                value without error for both c_ref and -c_ref.</span>
<span class="sd">            **kwargs: Keyword arguments passed to the get_fermi function.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The Fermi level. Note, the value is possibly interpolated or</span>
<span class="sd">            extrapolated and must be used with caution.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_fermi</span><span class="p">(</span><span class="n">concentration</span><span class="p">,</span> <span class="n">temperature</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">warn</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>

            <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">c_ref</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">1e-10</span><span class="p">:</span>
                    <span class="n">concentration</span> <span class="o">=</span> <span class="mf">1e-10</span>

                <span class="c1"># max(10, ) is to avoid log(0&lt;x&lt;1) and log(1+x) both of which</span>
                <span class="c1"># are slow</span>
                <span class="n">f2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_fermi_interextrapolated</span><span class="p">(</span>
                    <span class="nb">max</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="nb">abs</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">*</span> <span class="mf">10.</span><span class="p">),</span> <span class="n">temperature</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                    <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">f1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_fermi_interextrapolated</span><span class="p">(</span>
                    <span class="o">-</span><span class="nb">max</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="nb">abs</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">*</span> <span class="mf">10.</span><span class="p">),</span> <span class="n">temperature</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                    <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">c2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_doping</span><span class="p">(</span><span class="n">f2</span><span class="p">,</span> <span class="n">temperature</span><span class="p">)))</span>
                <span class="n">c1</span> <span class="o">=</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_doping</span><span class="p">(</span><span class="n">f1</span><span class="p">,</span> <span class="n">temperature</span><span class="p">)))</span>
                <span class="n">slope</span> <span class="o">=</span> <span class="p">(</span><span class="n">f2</span> <span class="o">-</span> <span class="n">f1</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">c2</span> <span class="o">-</span> <span class="n">c1</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">f2</span> <span class="o">+</span> <span class="n">slope</span> <span class="o">*</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">*</span>
                                     <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">concentration</span><span class="p">))</span> <span class="o">-</span> <span class="n">c2</span><span class="p">)</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">f_ref</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_fermi_interextrapolated</span><span class="p">(</span>
                    <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">*</span> <span class="n">c_ref</span><span class="p">,</span> <span class="n">temperature</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                    <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">f_new</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_fermi_interextrapolated</span><span class="p">(</span>
                    <span class="n">concentration</span> <span class="o">/</span> <span class="mf">10.</span><span class="p">,</span> <span class="n">temperature</span><span class="p">,</span> <span class="n">warn</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
                <span class="n">clog</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">concentration</span><span class="p">))</span>
                <span class="n">c_newlog</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
                    <span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_doping</span><span class="p">(</span><span class="n">f_new</span><span class="p">,</span> <span class="n">temperature</span><span class="p">)))</span>
                <span class="n">slope</span> <span class="o">=</span> <span class="p">(</span><span class="n">f_new</span> <span class="o">-</span> <span class="n">f_ref</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">c_newlog</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">concentration</span><span class="p">)</span>
                                           <span class="o">*</span> <span class="mf">10.</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">f_new</span> <span class="o">+</span> <span class="n">slope</span> <span class="o">*</span> <span class="p">(</span><span class="n">clog</span> <span class="o">-</span> <span class="n">c_newlog</span><span class="p">)</span></div>

<div class="viewcode-block" id="FermiDos.get_fermi"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.FermiDos.get_fermi">[docs]</a>    <span class="k">def</span> <span class="nf">get_fermi</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">concentration</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">temperature</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span>
                  <span class="n">rtol</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.01</span><span class="p">,</span> <span class="n">nstep</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">50</span><span class="p">,</span> <span class="n">step</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.1</span><span class="p">,</span>
                  <span class="n">precision</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">8</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Finds the fermi level at which the doping concentration at the given</span>
<span class="sd">        temperature (T) is equal to concentration. A greedy algorithm is used</span>
<span class="sd">        where the relative error is minimized by calculating the doping at a</span>
<span class="sd">        grid which continually becomes finer.</span>

<span class="sd">        Args:</span>
<span class="sd">            concentration: The doping concentration in 1/cm^3. Negative values</span>
<span class="sd">                represent n-type doping and positive values represent p-type</span>
<span class="sd">                doping.</span>
<span class="sd">            temperature: The temperature in Kelvin.</span>
<span class="sd">            rtol: The maximum acceptable relative error.</span>
<span class="sd">            nstep: THe number of steps checked around a given fermi level.</span>
<span class="sd">            step: Initial step in energy when searching for the Fermi level.</span>
<span class="sd">            precision: Essentially the decimal places of calculated Fermi level.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The fermi level in eV.. Note that this is different from the default</span>
<span class="sd">            dos.efermi.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fermi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span>  <span class="c1"># initialize target fermi</span>
        <span class="n">relative_error</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)]</span>
        <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">precision</span><span class="p">):</span>
            <span class="n">frange</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="n">nstep</span><span class="p">,</span> <span class="n">nstep</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">step</span> <span class="o">+</span> <span class="n">fermi</span>
            <span class="n">calc_doping</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">get_doping</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">temperature</span><span class="p">)</span>
                                    <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">frange</span><span class="p">])</span>
            <span class="n">relative_error</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">calc_doping</span> <span class="o">/</span> <span class="n">concentration</span> <span class="o">-</span> <span class="mf">1.0</span><span class="p">)</span>
            <span class="n">fermi</span> <span class="o">=</span> <span class="n">frange</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">relative_error</span><span class="p">)]</span>
            <span class="n">step</span> <span class="o">/=</span> <span class="mf">10.0</span>

        <span class="k">if</span> <span class="nb">min</span><span class="p">(</span><span class="n">relative_error</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">rtol</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;Could not find fermi within </span><span class="si">{}% o</span><span class="s2">f concentration=</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="n">rtol</span> <span class="o">*</span> <span class="mi">100</span><span class="p">,</span> <span class="n">concentration</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">fermi</span></div>

<div class="viewcode-block" id="FermiDos.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.FermiDos.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns Dos object from dict representation of Dos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">dos</span> <span class="o">=</span> <span class="n">Dos</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;efermi&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energies&quot;</span><span class="p">],</span>
                  <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;densities&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>
        <span class="k">return</span> <span class="n">FermiDos</span><span class="p">(</span><span class="n">dos</span><span class="p">,</span> <span class="n">structure</span><span class="o">=</span><span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">]),</span>
                        <span class="n">nelecs</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;nelecs&quot;</span><span class="p">])</span></div>

<div class="viewcode-block" id="FermiDos.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.FermiDos.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of Dos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
                <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
                <span class="s2">&quot;energies&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">),</span>
                <span class="s2">&quot;densities&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="nb">list</span><span class="p">(</span><span class="n">dens</span><span class="p">)</span>
                              <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">dens</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
                <span class="s2">&quot;structure&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">,</span> <span class="s2">&quot;nelecs&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nelecs</span><span class="p">}</span></div></div>


<div class="viewcode-block" id="CompleteDos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos">[docs]</a><span class="k">class</span> <span class="nc">CompleteDos</span><span class="p">(</span><span class="n">Dos</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    This wrapper class defines a total dos, and also provides a list of PDos.</span>
<span class="sd">    Mainly used by pymatgen.io.vasp.Vasprun to create a complete Dos from</span>
<span class="sd">    a vasprun.xml file. You are unlikely to try to generate this object</span>
<span class="sd">    manually.</span>

<span class="sd">    .. attribute:: structure</span>

<span class="sd">        Structure associated with the CompleteDos.</span>

<span class="sd">    .. attribute:: pdos</span>

<span class="sd">        Dict of partial densities of the form {Site:{Orbital:{Spin:Densities}}}</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">total_dos</span><span class="p">,</span> <span class="n">pdoss</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            structure: Structure associated with this particular DOS.</span>
<span class="sd">            total_dos: total Dos for structure</span>
<span class="sd">            pdoss: The pdoss are supplied as an {Site:{Orbital:{</span>
<span class="sd">                Spin:Densities}}}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">total_dos</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="n">energies</span><span class="o">=</span><span class="n">total_dos</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
            <span class="n">densities</span><span class="o">=</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">total_dos</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span> <span class="o">=</span> <span class="n">pdoss</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">structure</span> <span class="o">=</span> <span class="n">structure</span>

<div class="viewcode-block" id="CompleteDos.get_site_orbital_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_site_orbital_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_orbital_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">,</span> <span class="n">orbital</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the Dos for a particular orbital of a particular site.</span>

<span class="sd">        Args:</span>
<span class="sd">            site: Site in Structure associated with CompleteDos.</span>
<span class="sd">            orbital: Orbital in the site.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Dos containing densities for orbital of site.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">[</span><span class="n">site</span><span class="p">][</span><span class="n">orbital</span><span class="p">])</span></div>

<div class="viewcode-block" id="CompleteDos.get_site_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_site_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the total Dos for a site (all orbitals).</span>

<span class="sd">        Args:</span>
<span class="sd">            site: Site in Structure associated with CompleteDos.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Dos containing summed orbital densities for site.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">site_dos</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">add_densities</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">[</span><span class="n">site</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
        <span class="k">return</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">site_dos</span><span class="p">)</span></div>

<div class="viewcode-block" id="CompleteDos.get_site_spd_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_site_spd_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_spd_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get orbital projected Dos of a particular site</span>

<span class="sd">        Args:</span>
<span class="sd">            site: Site in Structure associated with CompleteDos.</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict of {orbital: Dos}, e.g. {&quot;s&quot;: Dos object, ...}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">spd_dos</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">[</span><span class="n">site</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">orbital_type</span> <span class="o">=</span> <span class="n">_get_orb_type</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">orbital_type</span> <span class="ow">in</span> <span class="n">spd_dos</span><span class="p">:</span>
                <span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">add_densities</span><span class="p">(</span><span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">],</span> <span class="n">pdos</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">orb</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">densities</span> <span class="ow">in</span> <span class="n">spd_dos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

<div class="viewcode-block" id="CompleteDos.get_site_t2g_eg_resolved_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_site_t2g_eg_resolved_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_t2g_eg_resolved_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the t2g, eg projected DOS for a particular site.</span>

<span class="sd">        Args:</span>
<span class="sd">            site: Site in Structure associated with CompleteDos.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dict {&quot;e_g&quot;: Dos, &quot;t2g&quot;: Dos} containing summed e_g and t2g DOS</span>
<span class="sd">            for the site.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">t2g_dos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">eg_dos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">s</span> <span class="o">==</span> <span class="n">site</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">orb</span> <span class="ow">in</span> <span class="p">(</span><span class="n">Orbital</span><span class="o">.</span><span class="n">dxy</span><span class="p">,</span> <span class="n">Orbital</span><span class="o">.</span><span class="n">dxz</span><span class="p">,</span> <span class="n">Orbital</span><span class="o">.</span><span class="n">dyz</span><span class="p">):</span>
                        <span class="n">t2g_dos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pdos</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">orb</span> <span class="ow">in</span> <span class="p">(</span><span class="n">Orbital</span><span class="o">.</span><span class="n">dx2</span><span class="p">,</span> <span class="n">Orbital</span><span class="o">.</span><span class="n">dz2</span><span class="p">):</span>
                        <span class="n">eg_dos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pdos</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;t2g&quot;</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                           <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">add_densities</span><span class="p">,</span> <span class="n">t2g_dos</span><span class="p">)),</span>
                <span class="s2">&quot;e_g&quot;</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                           <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">add_densities</span><span class="p">,</span> <span class="n">eg_dos</span><span class="p">))}</span></div>

<div class="viewcode-block" id="CompleteDos.get_spd_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_spd_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_spd_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get orbital projected Dos.</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict of {orbital: Dos}, e.g. {&quot;s&quot;: Dos object, ...}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">spd_dos</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">orbital_type</span> <span class="o">=</span> <span class="n">_get_orb_type</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">orbital_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">spd_dos</span><span class="p">:</span>
                    <span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">add_densities</span><span class="p">(</span><span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">],</span> <span class="n">pdos</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">orb</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">densities</span> <span class="ow">in</span> <span class="n">spd_dos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

<div class="viewcode-block" id="CompleteDos.get_element_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_element_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_element_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get element projected Dos.</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict of {Element: Dos}</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">el_dos</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">site</span><span class="p">,</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">el</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">specie</span>
            <span class="k">for</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">el</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">el_dos</span><span class="p">:</span>
                    <span class="n">el_dos</span><span class="p">[</span><span class="n">el</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">el_dos</span><span class="p">[</span><span class="n">el</span><span class="p">]</span> <span class="o">=</span> <span class="n">add_densities</span><span class="p">(</span><span class="n">el_dos</span><span class="p">[</span><span class="n">el</span><span class="p">],</span> <span class="n">pdos</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">el</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">el</span><span class="p">,</span> <span class="n">densities</span> <span class="ow">in</span> <span class="n">el_dos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

<div class="viewcode-block" id="CompleteDos.get_element_spd_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.get_element_spd_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_element_spd_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">el</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get element and spd projected Dos</span>

<span class="sd">        Args:</span>
<span class="sd">            el: Element in Structure.composition associated with CompleteDos</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict of {Element: {&quot;S&quot;: densities, &quot;P&quot;: densities, &quot;D&quot;: densities}}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">el</span> <span class="o">=</span> <span class="n">get_el_sp</span><span class="p">(</span><span class="n">el</span><span class="p">)</span>
        <span class="n">el_dos</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">site</span><span class="p">,</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">site</span><span class="o">.</span><span class="n">specie</span> <span class="o">==</span> <span class="n">el</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">orbital_type</span> <span class="o">=</span> <span class="n">_get_orb_type</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">orbital_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">el_dos</span><span class="p">:</span>
                        <span class="n">el_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">el_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> \
                            <span class="n">add_densities</span><span class="p">(</span><span class="n">el_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">],</span> <span class="n">pdos</span><span class="p">)</span>

        <span class="k">return</span> <span class="p">{</span><span class="n">orb</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">densities</span> <span class="ow">in</span> <span class="n">el_dos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">spin_polarization</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates spin polarization at Fermi level.</span>

<span class="sd">        See Sanvito et al., doi: 10.1126/sciadv.1602241 for</span>
<span class="sd">        an example usage.</span>

<span class="sd">        :return (float): spin polarization in range [0, 1],</span>
<span class="sd">        will also return NaN if spin polarization ill-defined</span>
<span class="sd">        (e.g. for insulator)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">n_F</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_interpolated_value</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">)</span>

        <span class="n">n_F_up</span> <span class="o">=</span> <span class="n">n_F</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">up</span><span class="p">]</span>
        <span class="n">n_F_down</span> <span class="o">=</span> <span class="n">n_F</span><span class="p">[</span><span class="n">Spin</span><span class="o">.</span><span class="n">down</span><span class="p">]</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">n_F_up</span> <span class="o">+</span> <span class="n">n_F_down</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># only well defined for metals or half-mteals</span>
            <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="s1">&#39;NaN&#39;</span><span class="p">)</span>

        <span class="n">spin_polarization</span> <span class="o">=</span> <span class="p">(</span><span class="n">n_F_up</span> <span class="o">-</span> <span class="n">n_F_down</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">n_F_up</span> <span class="o">+</span> <span class="n">n_F_down</span><span class="p">)</span>

        <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">spin_polarization</span><span class="p">)</span>

<div class="viewcode-block" id="CompleteDos.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns CompleteDos object from dict representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">tdos</span> <span class="o">=</span> <span class="n">Dos</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
        <span class="n">struct</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">])</span>
        <span class="n">pdoss</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;pdos&quot;</span><span class="p">])):</span>
            <span class="n">at</span> <span class="o">=</span> <span class="n">struct</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="n">orb_dos</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">orb_str</span><span class="p">,</span> <span class="n">odos</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;pdos&quot;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">orb</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">[</span><span class="n">orb_str</span><span class="p">]</span>
                <span class="n">orb_dos</span><span class="p">[</span><span class="n">orb</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">v</span>
                                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">odos</span><span class="p">[</span><span class="s2">&quot;densities&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">pdoss</span><span class="p">[</span><span class="n">at</span><span class="p">]</span> <span class="o">=</span> <span class="n">orb_dos</span>
        <span class="k">return</span> <span class="n">CompleteDos</span><span class="p">(</span><span class="n">struct</span><span class="p">,</span> <span class="n">tdos</span><span class="p">,</span> <span class="n">pdoss</span><span class="p">)</span></div>

<div class="viewcode-block" id="CompleteDos.as_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.CompleteDos.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of CompleteDos.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="s2">&quot;efermi&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span>
             <span class="s2">&quot;structure&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
             <span class="s2">&quot;energies&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">),</span>
             <span class="s2">&quot;densities&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">spin</span><span class="p">):</span> <span class="nb">list</span><span class="p">(</span><span class="n">dens</span><span class="p">)</span>
                           <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">dens</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">densities</span><span class="o">.</span><span class="n">items</span><span class="p">()},</span>
             <span class="s2">&quot;pdos&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">at</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">:</span>
                <span class="n">dd</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">[</span><span class="n">at</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">dd</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">orb</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;densities&quot;</span><span class="p">:</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">spin</span><span class="p">)):</span> <span class="nb">list</span><span class="p">(</span><span class="n">dens</span><span class="p">)</span> <span class="k">for</span> <span class="n">spin</span><span class="p">,</span> <span class="n">dens</span> <span class="ow">in</span> <span class="n">pdos</span><span class="o">.</span><span class="n">items</span><span class="p">()}}</span>
                <span class="n">d</span><span class="p">[</span><span class="s2">&quot;pdos&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dd</span><span class="p">)</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;atom_dos&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">at</span><span class="p">):</span> <span class="n">dos</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">at</span><span class="p">,</span> <span class="n">dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_element_dos</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;spd_dos&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">orb</span><span class="p">):</span> <span class="n">dos</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_spd_dos</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">d</span></div>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&quot;Complete DOS for &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span></div>


<div class="viewcode-block" id="LobsterCompleteDos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.LobsterCompleteDos">[docs]</a><span class="k">class</span> <span class="nc">LobsterCompleteDos</span><span class="p">(</span><span class="n">CompleteDos</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Extended CompleteDOS for Lobster</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="LobsterCompleteDos.get_site_orbital_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.LobsterCompleteDos.get_site_orbital_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_orbital_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">,</span> <span class="n">orbital</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the Dos for a particular orbital of a particular site.</span>

<span class="sd">        Args:</span>
<span class="sd">            site: Site in Structure associated with CompleteDos.</span>
<span class="sd">            orbital: principal quantum number and orbital in string format, e.g. &quot;4s&quot;.</span>
<span class="sd">                    possible orbitals are: &quot;s&quot;, &quot;p_y&quot;, &quot;p_z&quot;, &quot;p_x&quot;, &quot;d_xy&quot;, &quot;d_yz&quot;, &quot;d_z^2&quot;,</span>
<span class="sd">                    &quot;d_xz&quot;, &quot;d_x^2-y^2&quot;, &quot;f_y(3x^2-y^2)&quot;, &quot;f_xyz&quot;,</span>
<span class="sd">                    &quot;f_yz^2&quot;, &quot;f_z^3&quot;, &quot;f_xz^2&quot;, &quot;f_z(x^2-y^2)&quot;, &quot;f_x(x^2-3y^2)&quot;</span>
<span class="sd">                    In contrast to the Cohpcar and the Cohplist objects, the strings from the Lobster files are used</span>

<span class="sd">        Returns:</span>
<span class="sd">            Dos containing densities of an orbital of a specific site.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;s&quot;</span><span class="p">,</span> <span class="s2">&quot;p_y&quot;</span><span class="p">,</span> <span class="s2">&quot;p_z&quot;</span><span class="p">,</span> <span class="s2">&quot;p_x&quot;</span><span class="p">,</span> <span class="s2">&quot;d_xy&quot;</span><span class="p">,</span> <span class="s2">&quot;d_yz&quot;</span><span class="p">,</span> <span class="s2">&quot;d_z^2&quot;</span><span class="p">,</span> <span class="s2">&quot;d_xz&quot;</span><span class="p">,</span> <span class="s2">&quot;d_x^2-y^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_y(3x^2-y^2)&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;f_xyz&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;f_yz^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_z^3&quot;</span><span class="p">,</span> <span class="s2">&quot;f_xz^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_z(x^2-y^2)&quot;</span><span class="p">,</span> <span class="s2">&quot;f_x(x^2-3y^2)&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;orbital is not correct&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="p">[</span><span class="n">site</span><span class="p">][</span><span class="n">orbital</span><span class="p">])</span></div>

<div class="viewcode-block" id="LobsterCompleteDos.get_site_t2g_eg_resolved_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.LobsterCompleteDos.get_site_t2g_eg_resolved_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_site_t2g_eg_resolved_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the t2g, eg projected DOS for a particular site.</span>
<span class="sd">        Args:</span>
<span class="sd">            site: Site in Structure associated with CompleteDos.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dict {&quot;e_g&quot;: Dos, &quot;t2g&quot;: Dos} containing summed e_g and t2g DOS</span>
<span class="sd">            for the site.</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Are the orbitals correctly oriented? Are you sure?&quot;</span><span class="p">)</span>
        <span class="n">t2g_dos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">eg_dos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">s</span> <span class="o">==</span> <span class="n">site</span><span class="p">:</span>

                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">_get_orb_lobster</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="n">Orbital</span><span class="o">.</span><span class="n">dxy</span><span class="p">,</span> <span class="n">Orbital</span><span class="o">.</span><span class="n">dxz</span><span class="p">,</span> <span class="n">Orbital</span><span class="o">.</span><span class="n">dyz</span><span class="p">):</span>
                        <span class="n">t2g_dos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pdos</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">_get_orb_lobster</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="n">Orbital</span><span class="o">.</span><span class="n">dx2</span><span class="p">,</span> <span class="n">Orbital</span><span class="o">.</span><span class="n">dz2</span><span class="p">):</span>
                        <span class="n">eg_dos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pdos</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;t2g&quot;</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                           <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">add_densities</span><span class="p">,</span> <span class="n">t2g_dos</span><span class="p">)),</span>
                <span class="s2">&quot;e_g&quot;</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span>
                           <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">add_densities</span><span class="p">,</span> <span class="n">eg_dos</span><span class="p">))}</span></div>

<div class="viewcode-block" id="LobsterCompleteDos.get_spd_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.LobsterCompleteDos.get_spd_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_spd_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get orbital projected Dos.</span>
<span class="sd">        For example, if 3s and 4s are included in the basis of some element, they will be both summed in the orbital</span>
<span class="sd">        projected DOS</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict of {orbital: Dos}, e.g. {&quot;s&quot;: Dos object, ...}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">spd_dos</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">orbital_type</span> <span class="o">=</span> <span class="n">_get_orb_type_lobster</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">orbital_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">spd_dos</span><span class="p">:</span>
                    <span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">add_densities</span><span class="p">(</span><span class="n">spd_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">],</span> <span class="n">pdos</span><span class="p">)</span>

        <span class="k">return</span> <span class="p">{</span><span class="n">orb</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">densities</span> <span class="ow">in</span> <span class="n">spd_dos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

<div class="viewcode-block" id="LobsterCompleteDos.get_element_spd_dos"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.LobsterCompleteDos.get_element_spd_dos">[docs]</a>    <span class="k">def</span> <span class="nf">get_element_spd_dos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">el</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get element and spd projected Dos</span>


<span class="sd">        Args:</span>
<span class="sd">            el: Element in Structure.composition associated with LobsterCompleteDos</span>

<span class="sd">        Returns:</span>
<span class="sd">            dict of {Element: {&quot;S&quot;: densities, &quot;P&quot;: densities, &quot;D&quot;: densities}}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">el</span> <span class="o">=</span> <span class="n">get_el_sp</span><span class="p">(</span><span class="n">el</span><span class="p">)</span>
        <span class="n">el_dos</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">site</span><span class="p">,</span> <span class="n">atom_dos</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">pdos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">site</span><span class="o">.</span><span class="n">specie</span> <span class="o">==</span> <span class="n">el</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">pdos</span> <span class="ow">in</span> <span class="n">atom_dos</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">orbital_type</span> <span class="o">=</span> <span class="n">_get_orb_type_lobster</span><span class="p">(</span><span class="n">orb</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">orbital_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">el_dos</span><span class="p">:</span>
                        <span class="n">el_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">pdos</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">el_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">]</span> <span class="o">=</span> \
                            <span class="n">add_densities</span><span class="p">(</span><span class="n">el_dos</span><span class="p">[</span><span class="n">orbital_type</span><span class="p">],</span> <span class="n">pdos</span><span class="p">)</span>

        <span class="k">return</span> <span class="p">{</span><span class="n">orb</span><span class="p">:</span> <span class="n">Dos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">efermi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">energies</span><span class="p">,</span> <span class="n">densities</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">orb</span><span class="p">,</span> <span class="n">densities</span> <span class="ow">in</span> <span class="n">el_dos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span></div>

<div class="viewcode-block" id="LobsterCompleteDos.from_dict"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.LobsterCompleteDos.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: CompleteDos object from dict representation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">tdos</span> <span class="o">=</span> <span class="n">Dos</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
        <span class="n">struct</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">])</span>
        <span class="n">pdoss</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;pdos&quot;</span><span class="p">])):</span>
            <span class="n">at</span> <span class="o">=</span> <span class="n">struct</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="n">orb_dos</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">orb_str</span><span class="p">,</span> <span class="n">odos</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;pdos&quot;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">orb</span> <span class="o">=</span> <span class="n">orb_str</span>
                <span class="n">orb_dos</span><span class="p">[</span><span class="n">orb</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">Spin</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)):</span> <span class="n">v</span>
                                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">odos</span><span class="p">[</span><span class="s2">&quot;densities&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
            <span class="n">pdoss</span><span class="p">[</span><span class="n">at</span><span class="p">]</span> <span class="o">=</span> <span class="n">orb_dos</span>
        <span class="k">return</span> <span class="n">LobsterCompleteDos</span><span class="p">(</span><span class="n">struct</span><span class="p">,</span> <span class="n">tdos</span><span class="p">,</span> <span class="n">pdoss</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="add_densities"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.add_densities">[docs]</a><span class="k">def</span> <span class="nf">add_densities</span><span class="p">(</span><span class="n">density1</span><span class="p">,</span> <span class="n">density2</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Method to sum two densities.</span>

<span class="sd">    Args:</span>
<span class="sd">        density1: First density.</span>
<span class="sd">        density2: Second density.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Dict of {spin: density}.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">{</span><span class="n">spin</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">density1</span><span class="p">[</span><span class="n">spin</span><span class="p">])</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">density2</span><span class="p">[</span><span class="n">spin</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">spin</span> <span class="ow">in</span> <span class="n">density1</span><span class="o">.</span><span class="n">keys</span><span class="p">()}</span></div>


<span class="k">def</span> <span class="nf">_get_orb_type</span><span class="p">(</span><span class="n">orb</span><span class="p">):</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">orb</span><span class="o">.</span><span class="n">orbital_type</span>
    <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">orb</span>


<div class="viewcode-block" id="f0"><a class="viewcode-back" href="../../../pymatgen.electronic_structure.dos.html#pymatgen.electronic_structure.dos.f0">[docs]</a><span class="k">def</span> <span class="nf">f0</span><span class="p">(</span><span class="n">E</span><span class="p">,</span> <span class="n">fermi</span><span class="p">,</span> <span class="n">T</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns the equilibrium fermi-dirac.</span>
<span class="sd">    Args:</span>
<span class="sd">        E (float): energy in eV</span>
<span class="sd">        fermi (float): the fermi level in eV</span>
<span class="sd">        T (float): the temperature in kelvin</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="mf">1.</span> <span class="o">/</span> <span class="p">(</span><span class="mf">1.</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">((</span><span class="n">E</span> <span class="o">-</span> <span class="n">fermi</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">_cd</span><span class="p">(</span><span class="s2">&quot;Boltzmann constant in eV/K&quot;</span><span class="p">)</span> <span class="o">*</span> <span class="n">T</span><span class="p">)))</span></div>


<span class="k">def</span> <span class="nf">_get_orb_type_lobster</span><span class="p">(</span><span class="n">orb</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Args:</span>
<span class="sd">     orb: string representation of orbital</span>
<span class="sd">    Returns:</span>
<span class="sd">     OrbitalType</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">orb_labs</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;s&quot;</span><span class="p">,</span> <span class="s2">&quot;p_y&quot;</span><span class="p">,</span> <span class="s2">&quot;p_z&quot;</span><span class="p">,</span> <span class="s2">&quot;p_x&quot;</span><span class="p">,</span> <span class="s2">&quot;d_xy&quot;</span><span class="p">,</span> <span class="s2">&quot;d_yz&quot;</span><span class="p">,</span> <span class="s2">&quot;d_z^2&quot;</span><span class="p">,</span>
                <span class="s2">&quot;d_xz&quot;</span><span class="p">,</span> <span class="s2">&quot;d_x^2-y^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_y(3x^2-y^2)&quot;</span><span class="p">,</span> <span class="s2">&quot;f_xyz&quot;</span><span class="p">,</span>
                <span class="s2">&quot;f_yz^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_z^3&quot;</span><span class="p">,</span> <span class="s2">&quot;f_xz^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_z(x^2-y^2)&quot;</span><span class="p">,</span> <span class="s2">&quot;f_x(x^2-3y^2)&quot;</span><span class="p">]</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">orbital</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">orb_labs</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">orb</span><span class="p">[</span><span class="mi">1</span><span class="p">:]))</span>
        <span class="k">return</span> <span class="n">orbital</span><span class="o">.</span><span class="n">orbital_type</span>
    <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Orb not in list&quot;</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_get_orb_lobster</span><span class="p">(</span><span class="n">orb</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Args:</span>
<span class="sd">        orb: string representation of orbital</span>
<span class="sd">    Returns:</span>
<span class="sd">         Orbital</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">orb_labs</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;s&quot;</span><span class="p">,</span> <span class="s2">&quot;p_y&quot;</span><span class="p">,</span> <span class="s2">&quot;p_z&quot;</span><span class="p">,</span> <span class="s2">&quot;p_x&quot;</span><span class="p">,</span> <span class="s2">&quot;d_xy&quot;</span><span class="p">,</span> <span class="s2">&quot;d_yz&quot;</span><span class="p">,</span> <span class="s2">&quot;d_z^2&quot;</span><span class="p">,</span>
                <span class="s2">&quot;d_xz&quot;</span><span class="p">,</span> <span class="s2">&quot;d_x^2-y^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_y(3x^2-y^2)&quot;</span><span class="p">,</span> <span class="s2">&quot;f_xyz&quot;</span><span class="p">,</span>
                <span class="s2">&quot;f_yz^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_z^3&quot;</span><span class="p">,</span> <span class="s2">&quot;f_xz^2&quot;</span><span class="p">,</span> <span class="s2">&quot;f_z(x^2-y^2)&quot;</span><span class="p">,</span> <span class="s2">&quot;f_x(x^2-3y^2)&quot;</span><span class="p">]</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">orbital</span> <span class="o">=</span> <span class="n">Orbital</span><span class="p">(</span><span class="n">orb_labs</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">orb</span><span class="p">[</span><span class="mi">1</span><span class="p">:]))</span>
        <span class="k">return</span> <span class="n">orbital</span>
    <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Orb not in list&quot;</span><span class="p">)</span>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.electronic_structure.dos</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>